package io.github.luons.mediator.core.spi.cube;

import com.google.common.base.Preconditions;
import lombok.Data;

import java.io.Serializable;
import java.util.Map;

/**
 * Dimension
 *
 * @author : luons
 */
@Data
public class Dimension extends BaseColumn implements Serializable {

    /**
     * code
     */
    private String code;

    public Dimension() {
    }

    public Dimension(String code, String column) {
        Preconditions.checkNotNull(code, ("dimension code cannot be null"));
        Preconditions.checkNotNull(column, ("dimension column cannot be null"));
        this.code = code;
        this.column = column;
        this.alias = column;
    }

    public Dimension(String code, String column, String alias) {
        Preconditions.checkNotNull(code, ("dimension code cannot be null"));
        Preconditions.checkNotNull(column, ("dimension column cannot be null"));
        this.code = code;
        this.column = column;
        this.alias = alias;
    }

    public Dimension(String code, Column column) {
        Preconditions.checkNotNull(code, ("dimension code cannot be null"));
        Preconditions.checkNotNull(column, ("dimension column cannot be null"));
        this.code = code;
        this.column = column.getColumn();
        this.alias = column.getAlias();
    }

    public Object value(Map<String, Object> data) {
        return data.get(getAlias());
    }

}
